﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Threading;
using DoxygenBrowser.Common.Model;
using DoxygenBrowser.Common.Parser;
using System.IO;
using DoxygenBrowser.Common.InOut;
using DoxygenBrowserAddin.Data;

namespace DoxygenBrowserAddin.Controller
{
  public class TokenDictionaryLoader
  {
    private string _strTokenFilePath;

    private TokenDictionary _tokenDictionary;
    public TokenDictionary TokenDictionary
    {
      get
      {
        return _tokenDictionary;
      }
    }

    private void WorkerThreadFunction()
    {
      // parse or load the token dictionary

    }

    public TokenDictionaryLoader(string strTokenFilePath)
    {
      _strTokenFilePath = strTokenFilePath;
      _tokenDictionary = new TokenDictionary();
    }

    public bool IsLoading
    {
      get { return false; }
    }

    public void Process()
    {
      TokenFileParser parser = new TokenFileParser();
      StreamReader txtReader = new StreamReader(_strTokenFilePath, Encoding.ASCII);
      parser.TokenAddedEvent +=new EventHandler<TokenAddedEventArgs>(this.HandleTokenAdded);
      parser.Parser(txtReader);
    }

    public void Stop()
    {
      
    }

    public void HandleTokenAdded(object sender, TokenAddedEventArgs e)
    {
      _tokenDictionary.AddTokenEntry(e.TokenIdentifier.GetNormName(), e.FileLocation);
    }
      

    public void OnUpdateWorkStatus()
    {
      
    }

    public void OnCompletedWork()
    {
      
    }
  }
}
